package com.hhf.job.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hhf.job.entity.BaseJobLog;
import com.hhf.job.mapper.BaseJobLogMapper;
import com.hhf.job.service.BaseJobLogService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class BaseJobLogServiceImpl extends ServiceImpl<BaseJobLogMapper, BaseJobLog> implements BaseJobLogService {
    @Override
    public BaseJobLog getJobLogByLogId(Long logId) {
        QueryWrapper<BaseJobLog> qw = new QueryWrapper<>();
        qw.eq("log_id", logId);
        qw.last("limit 1");
        return getOne(qw);
    }

    @Override
    public Page<BaseJobLog> getJobLogPage(Page<BaseJobLog> page, Integer jobId) {
        OrderItem orderItem= OrderItem.desc("log_id");
        ArrayList<OrderItem> orders = new ArrayList<>();
        orders.add(orderItem);
        page.setOrders(orders);
        return baseMapper.getJobLogPage(page, jobId);
    }
}
